#include "client.h"

Client :: Client () {
	accounts = NULL;
	bank = NULL;
	num_transactions = 0;
	num_accounts = 0;
	thread_num = 0;
	rand = NULL;
}

Client :: Client (int account_info [], int number_of_transactions, int num_acct) {
	accounts = account_info;
	num_transactions = number_of_transactions;
	thread_num = 0;
	num_accounts = num_acct;
	bank = NULL;
	rand = NULL;
}

Client :: ~Client () {}

void Client :: thread_method () {
	int action;
	int amount;
	int account;

	for (int i = 0; i < num_transactions; i++) {
		// Decide if we want to withdraw/deposit
		action = rand -> get_random (2);

		// Decide how much we want to withdraw/deposit
		amount = rand -> get_random (301);

		if (amount < 20) {
			amount = 20;
		}

		// Decide which account we want to interact with
		account = rand -> get_random (num_accounts);

		// Withdraw/Deposit from/to the bank
		bank -> action (action, amount, account, thread_num, i);
	}
}

void Client :: set_thread_number (int number) {
	thread_num = number;
}

void Client :: set_bank (Bank * b) {
	bank = b;
}

void Client :: set_rand (Random_Generator * random) {
	rand = random;
}

